package com.yanyu.space.common.sleuth.rocket;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author gz
 */
@Aspect
@Slf4j
public class StreamBridgeAspect {
    @Around("execution (public boolean org.springframework.cloud.stream.function.StreamBridge.send(String, String, Object, org.springframework.util.MimeType))")
    public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {

        Object result = null;
        try {
            Object[] args = pjp.getArgs();
            System.out.println("==============="+args[0]);
            StreamBridgeContext.threadLocal.remove();
            result = pjp.proceed();
        } catch (Throwable e) {
            log.error("{}", e.getMessage(), e);
        } finally {
            StreamBridgeContext.threadLocal.remove();
        }
        return result;

    }
}
